﻿<%@ Page Title="" Language="C#" MasterPageFile="~/templet/blank.master" AutoEventWireup="true"
    CodeFile="userRegister.aspx.cs" Inherits="user_test" %>
  
<asp:Content ID="Content2" ContentPlaceHolderID="ContentPlaceHolder1" runat="Server">
    <script src="/js/dialog.js" type="text/javascript"></script>
  <link href="/css/dialog.css" rel="stylesheet" type="text/css" />
  <style>
  #dialog1
  {
      width:400px;
      }
     #dialog1 .content
  {
      width:380px;
      }  
  </style>
      <br>
    <div id="content" style="margin auto 0px;" class="w1000 d_an_cen">
        <h1 style="font-weight: bold;padding-left: 100px; font-size:14px; margin-bottom:20px;">
            用户注册<br><div id="processbar"></div></h1>
        <div class="f_l" style="padding-left: 100px;">
            <span class="m">登陆用Email邮箱:</span><br />
            <input id="email" name="form_email" type="text" size="24" maxlength="60" value=""
                onblur="check_email();" class="basic-input" />
            <span id="e_hint" class="attn hidden">请输入Email地址</span>
            <br />
            <div id="e_correct">
                <span class="pl">您的邮箱作为登录用户。</span>
            </div>
            <br />
            <span class="m">您的登录密码:</span><br />
            <input id="password" name="form_password" type="password" size="10" maxlength="20"
                value="" onblur="check_password();" class="basic-input" />
            <span id="p_hint" class="attn hidden">请输入密码</span>
            <br />
            <span class="pl">最少6个字符，请使用英文字母（区分大小写）、符号或数字。</span>
            <br />
            <br />
            <span class="m">您的名字:</span><br />
            <input id="i_name" name="form_name" type="text" size="10" maxlength="15" value=""
                onblur="check_name();" class="basic-input" />
            <span id="n_hint" class="attn hidden">请输入你的名字</span>
            <br />
            <span class="pl">中、英文均可。2-10个字</span>
            <script>
                var email = $("#email"), e_hint = $("#e_hint"), e_correct = $("#e_correct");
                var passwd = $("#password"), p_hint = $("#p_hint");
                var f_name = $("#i_name"), n_hint = $("#n_hint");
                var button = $("#button");
                var email_reg = /^[_\.0-9a-zA-Z+-]+@([0-9a-zA-Z]+[0-9a-zA-Z-]*\.)+[a-zA-Z]{2,4}$/;
                var passwd_reg = /^(\w){4,20}/;
                function check_email() {
                    e_hint.fadeOut();
                    var r = 1;
                    var s = email.attr('value');
                    if (!s) {
                        r = 0;
                        e_hint.fadeIn();
                    } else if (!email_reg.exec(s)) {
                        e_hint.html('请输入正确的Email地址');
                        e_hint.fadeIn();
                        r = 0;
                    } else {
                        e_hint.fadeOut();
                        showloading("正在检测Email可用性..");
                        $.ajax({
                            type: "POST",
                            contentType: "application/json",
                            url: "/webservices/login.asmx/hadreg",
                            data: "{email:'" + s + "'}",
                            dataType: "json",
                            error: function (x, e) { },
                            success: function (msg) {
                                if (msg.d == "1") {
                                    e_hint.html('该Email已经注册过');
                                    e_hint.fadeIn();
                                    removeLoading();
                                    r = 0;
                                }
                                else {
                                    r = 1;
                                    e_hint.fadeOut();
                                    removeLoading();
                                }

                            }
                        });

                    }


                    return r;
                }


                function check_password() {
                    var r = 1;

                    var s = passwd.attr('value');
                    if (!s) {
                        r = 0;
                    } else if (s.length < 6) {
                        p_hint.html('最少6个字符');
                        r = 0;
                    } else if (!passwd_reg.exec(s)) {
                        p_hint.html('请使用英文字母、符号或数字');
                        r = 0;
                    }
                    if (r) {
                        p_hint.fadeOut();
                    } else {
                        p_hint.fadeIn();
                    }
                    return r;
                }
                function check_name() {
                    var r = 1;
                    //alert("ws");
                    var s = f_name.attr('value');
                    //alert("ss");
                    if (!(s.length > 1 && s.length < 10)) {
                        n_hint.fadeIn();
                        r = 0;
                    } else {
                        n_hint.fadeOut();
                    }
                    return r;
                }
                function check_agree() {
                    if ($("#agreement").attr("checked") == 'checked') {
                        return true;
                    } else {
                        return false;
                    }
                }




                function buttonclick() {
                   
                   
                    
                        //判断协议是否勾取
                        if ($("#agreement").attr("checked") == 'checked')
                        {
                            $("#sumbittip").fadeOut();
                            //校验验证码
                            if ($("#validcode").attr("value") == "") {
                                $("#sumbittip").html('请输入验证码');
                                $("#sumbittip").fadeIn();
                                //alert("s");
                                return false;
                            }
                            else if (!((check_email()&&check_password())&&check_name())) {
                            return false;
                            }
                            else if ($.ajax({
                                type: "POST",
                                contentType: "application/json",
                                url: "/webservices/login.asmx/checkvalidcode",
                                data: "{code:'" + $("#validcode").attr("value") + "'}",
                                dataType: "json",
                                error: function (x, e) { },
                                success: function (msg) {
                                    if (msg.d == "0") {

                                        return false;
                                    }
                                    else {

                                        $("#sumbittip").fadeOut();
                                        return true;
                                    }

                                }
                            })) {

                                //提交注册
                                showloading("正在提交注册..");
                                // alert("s");
                                var senddt = "{email:'" + $("#email").attr("value") + "',pass:'" + $("#password").attr("value") + "',friendname:'" + $("#i_name").attr("value") + "',validcode:'" + $("#validcode").attr("value") + "'}";
                                $.ajax({ type: "POST",
                                    contentType: "application/json",
                                    url: "/webservices/login.asmx/register",
                                    data: senddt,
                                    dataType: "json",
                                    error: function (x, e) { },
                                    success: function (msg) {
                                        if (msg.d == "-1") {
                                            $("#sumbittip").html('验证码错误，请检查输入');
                                            $("#sumbittip").fadeIn();
                                            removeLoading();
                                        }
                                        else if (msg.d == "0") {
                                            $("#sumbittip").html('注册失败，请稍候再试');
                                            $("#sumbittip").fadeIn();
                                            removeLoading();
                                        }
                                        else if (msg.d == "-1") {
                                            e_hint.html('该Email已经注册过');
                                            e_hint.fadeIn();
                                        }
                                        else if (msg.d == "1") {
                                            $("#sumbittip").fadeOut();
                                            removeLoading();
                                            new Dialog('<table align=\'center\' width=\'300px\'><tr><td>恭喜您注册成功！</td><td><a href=\'/u/profilestep.aspx\'><input value=\'马上开始足迹之旅\' class=\'btnyellow150\' type=\'button\' id=\'btn_login\'></a></td></tr></table>', { id: 'dialog1' }).show();


                                        }
                                    }
                                });

                            }
                            else {
                                $("#sumbittip").html('验证码错误，请检查输入');
                                $("#sumbittip").fadeIn();
                                removeLoading();
                            }



                        }
                        else {
                            $("#sumbittip").html('同意协议才能提交注册');
                            $("#sumbittip").fadeIn();

                            return false;
                        }

                    
                }

            </script>
            <br />
            <p>
                <img src="/generateValidCode.aspx" alt="captcha" id="validimg" onclick="change()" /><script
                    language="javascript" type="text/javascript">
                                                                                                        document.getElementById("validimg").src = "/generateValidCode.aspx?t=" + Math.round(Math.random() * 1e17);

                                                                                                        function change() {
                                                                                                            document.getElementById("validimg").src = "/generateValidCode.aspx?t=" + Math.round(Math.random() * 1e17);
                                                                                                        }
                                                                                                        function button_onclick() {

                                                                                                        }

                </script><br />
                <br />
                <input type="text" id="validcode" name="captcha-solution" class="basic-input-validcode"
                    maxlength="10" />
                <span class="pl">上图验证码</span>
            </p>
            <label class="m">
                <input id="agreement" type="checkbox" name="form_agreement" />
                我已经认真阅读并同意足迹的《<a href="/policyagreement.aspx" target="_blank">使用协议</a>》。
            </label>
            <br />
            <br />
            <input id="button" class=" btn_yellow" type="button" value="提交注册" onclick="buttonclick();"
                onclick="return button_onclick()"  style=" margin-bottom:30px;"/>
            <div id="sumbittip" class="attn ">
                &nbsp;</div>
                <br>
        </div>
        <div class=" f_l" style="margin-left: 150px; width: 380px;">
            <h2>
                注册小贴士 &nbsp; &middot;&nbsp;&middot;&nbsp;&middot;&nbsp;&middot;&nbsp;&middot;&nbsp;&middot;&nbsp;
            </h2>
            <div class="pl" style=" line-height:30px">
                <p>
                    足迹绝不公开你的Email。</p>
                <p>
                    是否接受来自足迹的邮件提醒完全由你自己决定。</p>
                <p>
                    建议填写常用的Email地址，这样你就不会错过精彩内容。</p>
                <br />
                <p>
                    &gt; <a href="/u/userlogin.aspx">已注册请登录</a></p>
            </div>
        </div>
    </div>
</asp:Content>
